<?php
class AddTag extends Action {
	/*
	 * (non-PHPdoc) @see Action::execute()
	 */
	public function execute($params) {
		check_login ( ADMIN_LOGIN_PAGE );
		$rst ['success'] = false;
		$type = rqst ( 'type', 'tag' );
		$tag = rqst ( 'tag' );
		if (empty ( $tag )) {
			$rst ['msg'] = "空的标签";
		} else {
			$tagM = new WebTagModel ();
			$data ['tag'] = $tag;
			$data ['type'] = $type;
			if ($tagM->exist ( $data )) {
				$data ['msg'] = '标签已经存在';
			} else {
				$tag = $tagM->insert ( $data );
				if ($tag) {
					$rst ['success'] = true;
					$rst ['id'] = $tag ['tag_id'];
				} else {
					$rst ['msg'] = '保存标签时出错：' . $tagM->last_error_msg ();
				}
			}
		}
		return new JsonView ( $rst );
	}
}